<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.tjsinfo.tjsoa.system.vo.User"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>粮油集团办公自动化协作平台</title>
    <meta http-equiv="x-ua-compatible" content="ie=7" />
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="<%=basePath%>style/txlz7.css" rel="stylesheet" type="text/css" id="txlz7"/>
	<script type="text/javascript" src="<%=basePath%>js/ie.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/png.js"></script>
		<style type="text/css">
			td {
				font:12px/170% "宋体", "新宋体", "黑体"; color:#000;
			}
			th {
				font:12px/170% "宋体", "新宋体", "黑体"; color:#000;
			}
	</style>
	<style>
		 #divgroup {width:100%;height:100%;overflow:hidden;}
         .trBgColor { background-color:#A4D7E8; cursor: hand;}
         .trGroupColor { background-color:#C3EBF9; cursor: hand;}
         .trHiddivColor { background-color:#c3ebf9; cursor: hand;}
         
		.senddown {
			height: 27.1%;
			width: 98%;
			margin-top:0px;
			border:1px #9DB0BC solid;
			background:#fff;
			float:left;
			margin-left:3px;
		}
		.senddown1 {
			height: 80%;
			width: 98%;
			margin-top:6px;
			border:1px #9DB0BC solid;
			background:#fff;
			float:left;
			margin-left:3px;
		}
   </style>
                
	<script type='text/javascript' src='<%=basePath%>dwr/interface/AddressListGroupBo.js'></script>
	<script type='text/javascript' src='<%=basePath%>dwr/interface/AddressListUserBo.js'></script>
	<script type='text/javascript' src='<%=basePath%>dwr/interface/AddressListUserPageBo.js'></script>
	<script type='text/javascript' src="<%=basePath%>dwr/engine.js"></script>
	<script type='text/javascript' src="<%=basePath%>dwr/util.js"></script>
	
	<link href="<%=basePath %>ajaxFramework/ext-2.1/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="<%=basePath %>ajaxFramework/ext-2.1/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="<%=basePath %>ajaxFramework/ext-2.1/ext-all-debug.js"></script>
    <script type="text/javascript" src="<%=basePath %>ajaxFramework/ext-2.1/source/locale/ext-lang-zh_CN.js"></script>
    <script type="text/javascript" src="<%=basePath %>ajaxFramework/jQuery/jquery.js"></script>
	<script type="text/javascript" src="<%=basePath %>js/common/system/selectusertreecheck.js"></script>
	<%
		User user = (User)session.getAttribute("user");
		String group_id = (String)request.getAttribute("group_id");
		String user_page = (String)request.getAttribute("user_page");
		String user_id = (String)request.getAttribute("user_id");
		String first = (String)request.getAttribute("first");
		String moduleType = (String)request.getAttribute("moduleType");
		String state = (String)request.getAttribute("state");
		if(state == null)state = "";
	 %>
	<script type="text/javascript">
		var group_id = '<%=group_id %>';
		var intpage = <%=user_page %>;
		var first = '<%=first %>';
		var user_id = '<%=user_id %>';
		var copyid = '';
		var copygroup = '';
		var pagenum = '15';
		var state = '<%=state %>';
		if(intpage == '' || intpage == null){intpage = 1}
		
		function windowonload(){
			document.getElementById("right").style.height = document.body.clientHeight;
			document.getElementById("divgroup").style.height = 390;
			document.getElementById("tdindex").style.width = document.body.clientWidth-132;
			document.getElementById("tdindex").style.height = document.body.clientHeight-90;
			document.getElementById("divindex").style.height = document.body.clientHeight-165;
			if(first == "shi"){
				AddressListUserPageBo.getFirstPage(<%=user.getUser_id() %>,<%=moduleType %>,pagenum,ListUser);
			}else{
				AddressListUserPageBo.getFirstPage(<%=user.getUser_id() %>,<%=moduleType %>,pagenum,ListUser);
			}
		}
		
		var groupNum = 0;
		var fu = null;
		function Group(fuzhi){
			var divgroup = document.getElementById("divgroup");
			fu = fuzhi;
			groupNum = fu.length/2;
			var liebiaoGroup = '<table id="grouptable" border="0" width="129px" cellspacing="0" cellpadding="0">';
			var i = 0;
			for(var a=0;a<fu.length;a=a+2){
				if(fu[a] == group_id){//当此组为当前选中组ID
					//class=\"trGroupColor\"，此组变色、粗体
					liebiaoGroup += '<tr id="group'+i+'" class=\"trGroupColor\" onclick="GroupListUser(\''+fu[a]+'\')" onmouseup=\"ClickGroup('+i+');\"><td width="23px" height="24px" align="center"><img src="<%=basePath%>images/conicon.gif"/></td><td height="24px" valign="middle" style=\"font-weight: bold\">';
					if(fu[a+1].length>8){
						liebiaoGroup += '<a id=\"groupA'+i+'\" title=\"'+fu[a+1]+'\">'+fu[a+1].substring(0,8)+'</a></td></tr>';
					}else{
						liebiaoGroup += '<a id=\"groupA'+i+'\">'+fu[a+1]+'</a></td></tr>';
					}
				}else{
					//其余组onmouseover、onmouseout,鼠标悬停变色
					if(fu[a+1].length>8){
						liebiaoGroup += '<tr id="group'+i+'" onmouseover=\'this.className=\"trGroupColor\"\' onmouseout=\'this.className=\"\"\' onclick="GroupListUser(\''+fu[a]+'\')" onmouseup=\"ClickGroup('+i+');\"><td width="23px" height="24px" align="center"><img src="<%=basePath%>images/conicon.gif"/></td><td height="24px" valign="middle"><a id=\"groupA'+i+'\" title=\"'+fu[a+1]+'\">'+fu[a+1].substring(0,8)+'</a></td></tr>';
					}else{
						liebiaoGroup += '<tr id="group'+i+'" onmouseover=\'this.className=\"trGroupColor\"\' onmouseout=\'this.className=\"\"\' onclick="GroupListUser(\''+fu[a]+'\')" onmouseup=\"ClickGroup('+i+');\"><td width="23px" height="24px" align="center"><img src="<%=basePath%>images/conicon.gif"/></td><td height="24px" valign="middle"><a id=\"groupA'+i+'\">'+fu[a+1]+'</a></td></tr>';
					}
				}
				i++;
			}
			if(fu.length>30){
				document.getElementById("zushang").style.display = "block";
				document.getElementById("zuxia").style.display = "block";
			}else{
				document.getElementById("zushang").style.display = "none";
				document.getElementById("zuxia").style.display = "none";
			}
			liebiaoGroup += '</table>';
			divgroup.innerHTML= liebiaoGroup;
		}
		
        var groupA = -1;
        function ClickGroup(i){
			if(groupA!=-1)
			document.getElementById("group"+groupA).onmouseout = function(){this.className=''};
        	for(var a = 0 ; a<groupNum;a++ ){
				var b = document.getElementById("group"+a);
				var c = document.getElementById("groupA"+a);
				if(a == i){
					b.className="trGroupColor";
					c.style.fontWeight="bold";
					b.onmouseout = null;
					groupA = a;
				}else{
					c.style.fontWeight="100";
					b.className='';
				}
			}
        }
        
		function init(page){
			intpage=page;
			AddressListUserPageBo.getGotoPage(group_id,intpage,<%=moduleType %>,pagenum,ListUser);
		}
		
		function ListUser(addressListUser){
			if(first == "shi" || state == "return"){
				AddressListUserPageBo.getGroup(getGroup_id);
				first = "fou";
			}
			var divindex = document.getElementById("divindex");
			var liebiaoUser = '<table class="p_06" width=\"100%\" border=\"0\" cellspacing=\"0\"><tr><th width=\"4%\">&nbsp;</th><th width=\"8%\" style=\"text-align: center;\">姓名</th><th width=\"12%\" style=\"text-align: center;\">手机</th><th width=\"34%\" style=\"text-align: center;\">单位</th></tr>';
			if(addressListUser.length != 0){
			for(var i=0;i<addressListUser.length;i++){
				var id = addressListUser[i].id;
				var name = retrunString(addressListUser[i].userName,4,4);
				var name1 = addressListUser[i].userName;
				
				var mobile = addressListUser[i].mobile;if(mobile==null || mobile == '')mobile='&nbsp;'; else mobile = retrunString(mobile,11,11);
				var mobile1 = addressListUser[i].mobile;if(mobile1==null || mobile1 == '')mobile1='';
				
				var company = addressListUser[i].company;if(company==null || company == '')company='&nbsp;';else company = retrunString(company,24,18);
				var company1 = addressListUser[i].company;if(company1==null || company1 == '')company1='';
				
				if(copyid != null && copyid != ''){
					var a = copyid.split(",");
					var aa = 0;
					for(var j = 0;j<a.length;j++){
						if(a[j] == id){
							aa = 1;
							liebiaoUser += '<tr id="copyUser'+i+'" class="trBgColor"><td><input type="checkbox" name="copyUser" id="copyUser" onclick="copyClickUser('+i+',\''+id+'\');" checked="checked"/></td><td>'+name+'</td><td><a title="'+mobile1+'">'+mobile+'</a></td><td class="left_txt"><a title="'+company1+'">'+company+'</a></td></tr>';
						}
					}
					if(aa == 0){
						liebiaoUser += '<tr id="copyUser'+i+'"><td><input type="checkbox" name="copyUser" id="copyUser" onclick="copyClickUser('+i+',\''+id+'\');"/></td><td>'+name+'</td><td><a title="'+mobile1+'">'+mobile+'</a></td><td class="left_txt"><a title="'+company1+'">'+company+'</a></td></tr>';
					}
				}else{
					liebiaoUser += '<tr id="copyUser'+i+'"><td><input type="checkbox" name="copyUser" id="copyUser" onclick="copyClickUser('+i+',\''+id+'\');"/></td><td>'+name+'</td><td><a title="'+mobile1+'">'+mobile+'</a></td><td class="left_txt"><a title="'+company1+'">'+company+'</a></td></tr>';
				}
			}
			liebiaoUser += '<tr align=\"center\"><td colspan="7"><div class="page">';
                        
			AddressListUserPageBo.getPagecount({
			callback:function(pagecount) {
				//下拉框
			
			if(first == 'delete' && intpage == pagecount+1){
				intpage = pagecount;
				first = null;
			}
             var select="<select name=\"sel\">";
             for(var i=0;i<pagecount;i++){
                if((i+1)==intpage)
              select+="<option value=\""+(i+1)+"\" selected>"+(i+1)+"</option>";
              else
              select+="<option value=\""+(i+1)+"\">"+(i+1)+"</option>";              
             }
             select+="</select>";
             
             //链接条
             var linkstr="";
             if(intpage>pagecount)intpage=pagecount;
             
             if(intpage>1){
                linkstr+="&nbsp;&nbsp;<a href=\"javascript:init("+(Number(intpage)-1)+")\">上一页</a>";
             }
             if(intpage<pagecount){
                linkstr+="&nbsp;&nbsp;<a href=\"javascript:init("+(Number(intpage)+1)+")\">下一页</a>";
             }
             
             //按钮
             var btn="<input type='button' value='转到' onclick='init(sel.value)'/>";
             
             //  第XXX页/共XXX页
             var mix="<a>共"+pagecount+"页,当前为第"+intpage+"页</a>";
             
             divindex.innerHTML=liebiaoUser+mix+linkstr+'		'+select+'			'+btn;
             divindex.innerHTML+="</div></td></tr></table></form>";
			}
		});
		}else{
			liebiaoUser += '</table>';
		}
			divindex.innerHTML= liebiaoUser;
		}
		
		function copyClickUser(i,id){
			var b = document.getElementById("copyUser"+i);
			if(b.className == ""){
				b.className="trBgColor";
				copyid += id+",";
			}else{
			 	b.className="";
			 	copyid = copyid.replace(id+",", "");
			}
		}
		
		function getGroup_id(Group_id){
			group_id = Group_id;
			AddressListGroupBo.getGroup(<%=user.getUser_id() %>,<%=moduleType %>,Group);
		}
		
		function GroupListUser(groupid){
			group_id = groupid;
			user_id = '';
			intpage = 1;
			AddressListUserPageBo.getGotoPage(groupid,1,<%=moduleType %>,pagenum,ListUser);
		}
		
		function submitform(){
			var checkbox2 = document.getElementsByName('checkbox2');
			var length  = checkbox2.length;
			var sendusers = document.getElementById('sendusers').value;
			for(var a = 0; a<length; a++)
			{
				var check1 = checkbox2[a].value;
				sendusers += check1+",";	
			}
			if(sendusers == ''){
				Ext.MessageBox.alert('提示框','<nobr>请选择要发送给的系统用户<nobr>');
				return;
			}else{
				document.getElementById('sendusers').value = sendusers.substring(0,sendusers.length-1);
			}
			if(copyid != ''){
				document.getElementById('copyid').value = copyid.substring(0,copyid.length-1);
				document.form1.submit();
			}else{
				Ext.MessageBox.alert('提示框','<nobr>请选择发送的联系人信息<nobr>');
				return;
			}
		}
		
		window.onload = function(){
			initselectusertreecheck();
			windowonload();
			var tb = new Ext.Toolbar(
				{
					height:25
				}
			);
		
		    tb.render('menu');
			tb.add(
		    {
		            text:'确定',
		            iconCls: 'daohang',
		        	handler: function(){
		        		submitform();
					}
		    },
		    {
		            text:'返回',
		            iconCls: 'daohang',
		        	handler: function(){
		        		location.href="<%=basePath%>tjsinfo/tjsoa/addresslist/loginAddressList.do";
					}
		    }
		    );
			tb.addFill();
		    tb.addText('<img id="windowResize" src="<%=basePath%>images/m_icon05.gif;"><a style="font-weight:bold; color:black;line-height: 22px;">发送联系人</a>&nbsp;&nbsp;&nbsp;');
		}
	</script>
<script type="text/javascript">
	function retrunString(str,k,z){
		if(screen.width <= 1024){
			str = str.substring(0,z);
		}else{
			str = str.substring(0,k);
		}
		return str;
	}
	
	function ifsubmit(str,k,z){
		if(screen.width <= 1024){
			if(str.length > z)return false; else return true;
		}else{
			if(str.length > k)return false; else return true;
		}
	}
</script>
<%-- 向上向下滑动--%>
	 <script type="text/JavaScript">
var sh;
preLeft=0; currentLeft=0; stopscroll=false; getlimit=0;preTop=0; currentTop=0;
function scrollLeft()
{
	var marquees = document.getElementById("divgroup");
	if(stopscroll==true) return;
	preLeft=marquees.scrollTop;
	marquees.scrollTop+=2;
	if(preLeft==marquees.scrollTop)
	{
		//marquees.scrollLeft=templayer.offsetWidth-marqueesWidth+1;
	}
}

function scrollRight()
{
	var marquees = document.getElementById("divgroup");
	if(stopscroll==true) return;

	preLeft=marquees.scrollTop;
	marquees.scrollTop-=2;
	if(preLeft==marquees.scrollTop)
	{
		if(!getlimit)
		{
			marquees.scrollLeft=templayer.offsetWidth*2;
			getlimit=marquees.scrollLeft;
		}
		marquees.scrollLeft-=1;
	}
}

function Left()
{
	stopscroll = false;
	sh = setInterval("scrollLeft()",30);
}

function Right()
{
	stopscroll = false;
	sh = setInterval("scrollRight()",30);
}

function StopScroll()
{
	stopscroll = true;
	clearInterval( sh );
}
</script>
  </head>
  
  <body>
    <div id="right" style="width: 99%">
    <div style="height:90%">
    <form action="<%=basePath %>tjsinfo/tjsoa/addresslist/sendAddressListUser.do" name="form1" method="post">
  	<div id="menu" style="padding-top:4px;"></div>
	<input type="hidden" id="copyid" name="copyid"/>
	<input type="hidden" id="copygroup" name="copygroup"/>
	<input type="hidden" id="moduleType" name="moduleType" value="<%=moduleType %>"/>
	<input type="hidden" id="sendusers" name="sendusers"/>
	<input id="basePath" value="<%=basePath%>" type="hidden"/>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
          <tr>
            <td width="132px" valign="top" align="left" height="100%">
              <div class="conren" style="height: 450px">
                <div class="h"><table width="132px" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="22%" align="center"><img src="<%=basePath%>images/zuicon01.gif" /></td>
                        <td width="78%" align="left">联系人组</td>
                      </tr>
                    </table>
                </div>
                <div id="zushang" class="zuxia" onmouseout=StopScroll() onmouseover=Right() style='cursor:pointer;display: none;'></div>
                  <table width="132px" height="390px" border="0" cellspacing="0" cellpadding="0" id="grouptable">
                    <tr height="100%" valign="top">
                      <td>
                      	<div id="divgroup" style="height: 100%"></div>
                      	<DIV id=templayer style="LEFT: 0px; VISIBILITY: hidden; POSITION: absolute; TOP: 0px"></DIV>
                      </td>
                    </tr>
                </table>
                <div id="zuxia" class="zushang" onmouseout=StopScroll() onmouseover=Left() style='cursor:pointer;display: none;'></div>
              </div>
            </td>
            <td width="98%" valign="top" height="100%" id="tdindex">
               <div id="divindex" class="contab" style="width: 99%"></div>
               <div id="senddown" class="senddown" style="width: 99%;height: 110px">
               <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%" style="background-color: white">
               <tr>
                 <td class="fssxbg" align="center" colspan="4">
                 </td>
                </tr>
               	<tr>
               		<td width="5%"></td>
               		<td height="100%" valign="top">
               		请选择发送到的系统用户:<br/>
               		<input name="uuuuuuu" id="uuuuuuu" size="100">
               		<input type="button" value="选择" onclick="selectusertreecheckwinshow('sendusers','uuuuuuu','node2')"/>
               		</td>
               	</tr>
               	<tr>
                    <td colspan="4" align="center"><br /></td>
               	</tr>
               	<tr>
                    <td colspan="4" align="center">&nbsp;<br /></td>
               	</tr>
               </table>
               </div>
               </td>
      </table>
      	<input type="hidden" name="node2" id="node2"/>
      </form>
      </div>
</div>
<script type="text/javascript">
	<%
		if(state!=null && !"".equals(state)){
	%>
	Ext.MessageBox.alert('提示框','<nobr>发送成功</nobr>');
	<%
		}
	%>
</script>
  </body>
